package com.inspur.cmis.controller;

import java.io.File;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.commons.io.FileUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import com.inspur.cmis.constant.Constant;
import com.inspur.cmis.pojo.CMResults;
import com.inspur.cmis.pojo.CMResultsExt;
import com.inspur.cmis.pojo.CMass;
import com.inspur.cmis.pojo.CMassExt;
import com.inspur.cmis.pojo.CMlevel;
import com.inspur.cmis.pojo.CMlevelExt;
import com.inspur.cmis.pojo.CMltr;
import com.inspur.cmis.pojo.CMltrExt;
import com.inspur.cmis.pojo.LicenseList;
import com.inspur.cmis.pojo.LicenseListExt;
import com.inspur.cmis.pojo.Param;
import com.inspur.cmis.pojo.RewardPunishment;
import com.inspur.cmis.pojo.RewardPunishmentExt;
import com.inspur.cmis.pojo.User;
import com.inspur.cmis.pojo.WorkHistory;
import com.inspur.cmis.pojo.WorkHistoryExt;
import com.inspur.cmis.service.CMResultsService;
import com.inspur.cmis.service.CMassService;
import com.inspur.cmis.service.CMlevelService;
import com.inspur.cmis.service.CMltrService;
import com.inspur.cmis.service.LicenseListService;
import com.inspur.cmis.service.ParamService;
import com.inspur.cmis.service.RewardPunishmentService;
import com.inspur.cmis.service.WorkHistoryService;
@Controller
public class ClientManagerOtherInfoController {
	@Autowired
	private WorkHistoryService workHistoryService;
	@Autowired
	private ParamService paramService;
	@Autowired
	private RewardPunishmentService rpService;
	@Autowired
	private CMResultsService cmResultsService;
	@Autowired
	private LicenseListService licenseListService;
	@Autowired
	private CMassService cMassService;
	@Autowired
	private CMltrService cMltrService;
	@Autowired
	private CMlevelService cMlevelService;
	@RequestMapping("/clientMgrInfoOther1")
	public ModelAndView getAllInfoOtherByPage(@RequestParam(value = "pageNum", defaultValue = "1") int pageNum,HttpServletRequest req) {
		String userId = req.getParameter("userId");
//		if(userId == null) {
//			HttpSession session=req.getSession();
//			User user=(User)session.getAttribute("user");
//			userId=user.getUserId()+"";
//		}
		ModelAndView mv = new ModelAndView();
		//年度工作业绩
		List<CMResultsExt> resultList =new ArrayList<CMResultsExt>();
		//证照列表
		List<LicenseListExt> LLresultList =new ArrayList<LicenseListExt>();
		//奖惩
		List<RewardPunishmentExt> RPresultList = new ArrayList<RewardPunishmentExt>();
		//考核记录
		List<CMassExt> cmassresultList = new ArrayList<CMassExt>();
		//学习培训记录
		List<CMltrExt> cMltrresultList =new ArrayList<CMltrExt>();
		//工作经历
		List<WorkHistoryExt> workList = new ArrayList<WorkHistoryExt>();
		//等级认定
		List<CMlevelExt> cMlevelresultList = new ArrayList<CMlevelExt>();
		
		if (pageNum == 1) {// 默认查询第一个page页的数据
			//年度工作业绩
			HashMap<String, Object> map = new HashMap<String, Object>();
			map.put("userId", userId);
			String cmYear =req.getParameter("cmYear");
			map.put("cmYear",cmYear);
			String cmrkey = req.getParameter("cmrkey");
			map.put("cmrkey",cmrkey);
			resultList = cmResultsService.getCMResultsList(map);
			mv.addObject("resultList", resultList);
		}else if(pageNum == 2) {
			//证照列表
			HashMap<String, Object> map = new HashMap<String, Object>();
			map.put("userId", userId);
			String cmStartDate1 =req.getParameter("cmStartDate");
			if(cmStartDate1 !=null && cmStartDate1 !="") {
				SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd");
				Date cmStartDate=new Date();
				try {
					cmStartDate =sdf.parse(cmStartDate1);
				} catch (ParseException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				map.put("cmStartDate", cmStartDate);
			}
			String llkey =req.getParameter("llkey");
			map.put("llkey", llkey);
			LLresultList = licenseListService.getLicenseListList(map);
			mv.addObject("LLresultList", LLresultList);
			
		}else if(pageNum == 3){
			//奖惩
			HashMap<String, Object> map = new HashMap<String, Object>();
			map.put("userId", userId);
			String rpTpye=req.getParameter("rpTpye");
			map.put("rpTpye", rpTpye);
			String rpKey = req.getParameter("rpKey");
			map.put("rpKey",rpKey);
			RPresultList = rpService.getRewardPunishmentList(map);
			mv.addObject("RPresultList",RPresultList);
			
		}else if(pageNum == 4){
			//考核记录
			HashMap<String, Object> map = new HashMap<String, Object>();
			map.put("userId", userId);
			String gcdata1 =req.getParameter("gcdata");
			if(gcdata1 !=null && gcdata1 !="") {
				SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd");
				Date gcdata=new Date();
				try {
					gcdata =sdf.parse(gcdata1);
				} catch (ParseException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				map.put("gcdata", gcdata);
			}
			String clientgckey=req.getParameter("clientgckey");
			map.put("Clientgckey", clientgckey);
			cmassresultList = cMassService.getCMassList(map);
			mv.addObject("cmassresultList",cmassresultList);
		}else if(pageNum == 5) {
			//学习记录
			HashMap<String, Object> map = new HashMap<String, Object>();
			map.put("uesrId", userId);
			String trdate1 =req.getParameter("trdate");
			if(trdate1 !=null && trdate1 != "") {
				SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd");
				Date trdate=new Date();
				try {
					trdate=sdf.parse(trdate1);
				} catch (ParseException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				
				map.put("trdate", trdate);
			}
			String trsub =req.getParameter("trsub");
			map.put("trsub", trsub);
			String clienttkey =req.getParameter("clienttkey");
			map.put("Clienttkey", clienttkey);
			cMltrresultList = cMltrService.getCMltrList(map);
			mv.addObject("cMltrresultList",cMltrresultList);
			
		}else if(pageNum == 6){
			//等级认定
			HashMap<String, Object> map = new HashMap<String, Object>();
			map.put("uesrId", userId);
			String hotime1 =req.getParameter("hotime");
			if(hotime1 !=null && hotime1 !="") {
			SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd");
			Date hotime=new Date();
			try {
				hotime=sdf.parse(hotime1);
			} catch (ParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			map.put("hotime", hotime);
			}
			String holevel =req.getParameter("holevel");
			map.put("holevel", holevel);
			String clientlekey =req.getParameter("clientlekey");
			map.put("Clientlekey", clientlekey);
			cMlevelresultList = cMlevelService.getCMlevelList(map);
			mv.addObject("cMlevelresultList",cMlevelresultList);
			
			
		}else if (pageNum == 7) {
			//工作经历
			HashMap<String, Object> map = new HashMap<String, Object>();
			String whPosition= req.getParameter("whPosition");
			map.put("whPosition", whPosition);
			map.put("userId", userId);
			String whkey =req.getParameter("whkey");
			map.put("whkey", whkey);
			workList = workHistoryService.getWorkList(map);
			mv.addObject("workList", workList);
		}
		
		mv.addObject("userId", userId);
		mv.addObject("pageNum", pageNum);
		mv.setViewName("/manager/clientMgrInfoOther.jsp");
		return mv;
	}
	//添加年度业绩
	@RequestMapping("/addCMResults")
	public String addCMResults(CMResults cmResults, Model model,HttpSession session) {
		// 1.获取当前时间
		Date today = new Date();
		cmResults.setCmModificationDate(today);
		
		//维护人
		User user=(User)session.getAttribute("user");
		String whModifyPerson=user.getUserId()+"";
		cmResults.setCmModificationPerson(whModifyPerson);
		
		cmResultsService.addCMResults(cmResults);
		return "redirect:clientMgrInfoOther1?pageNum=1&userId="+cmResults.getUserId();
		
		
	}
	
	//查询CMResults 修改过度
		@RequestMapping("/modifyCMResults")
	public @ResponseBody List<CMResultsExt> getCMResults(String cmrkey) {
			HashMap<String, String> map=new HashMap<String, String>();
			map.put("cmrkey",cmrkey);
			List<CMResultsExt> resultList = cmResultsService.getCMResultsList(map);
			return resultList;
		}
	//修改年度业绩
	@RequestMapping("/updateCMResults")
	public String updateCMResults(CMResults cmResults, Model model,HttpSession session) {
		// 1.获取当前时间
		Date today = new Date();
		cmResults.setCmModificationDate(today);
		
		//维护人
		User user=(User)session.getAttribute("user");
		String whModifyPerson=user.getUserId()+"";
		cmResults.setCmModificationPerson(whModifyPerson);
		
		cmResultsService.updateCMResults(cmResults);
		System.out.println(cmResults.getCmrkey()+"==================================");
		return "redirect:clientMgrInfoOther1?pageNum=1&cmrkey="+cmResults.getCmrkey();
		
		
	}
	
	//添加LicenseList
		@RequestMapping("/addLicenseList")
	public  String addLicenseList(LicenseList LicenseList,Model model,HttpSession session,MultipartFile upload) {
		// 1.获取当前时间
				Date today = new Date();
				LicenseList.setCmModificationDate(today);
				//维护人
				User user=(User)session.getAttribute("user");
				String whModifyPerson=user.getUserId()+"";
				LicenseList.setCmModificationPerson(whModifyPerson);
				//文件上传
				
				String uploadFile_name = "";
				String newFileName = "";
				try {// 原始⽂件名称
					if (upload != null) {
				
						uploadFile_name = upload.getOriginalFilename();
						// 新⽂件名称
						if (!"".equals(uploadFile_name))
							newFileName = UUID.randomUUID().toString()
									+ uploadFile_name.substring(uploadFile_name
											.lastIndexOf("."));
						// 上传图⽚物理路径
						String url = session.getServletContext()
								.getRealPath("/LicenseList/upload");
						File uploadfile = new java.io.File(url + "/" + newFileName);
						File url1=new File(url);
						if (!url1.exists()) {
							url1.mkdirs();
						}
						upload.transferTo(uploadfile);
						LicenseList.setCmCertificateUrl(newFileName);
					}
				} catch (IllegalStateException e) {
					e.printStackTrace();
				} catch (IOException e) {
					e.printStackTrace();
				}
				licenseListService.addLicenseList(LicenseList);
				return "redirect:clientMgrInfoOther1?pageNum=2&userId="+LicenseList.getUserId();
	}

	//查询修改过度LicenseList
			@RequestMapping("/modifyLicenseList")
	public @ResponseBody List<LicenseListExt> getLicenseList(String llkey) {
				HashMap<String, String> map=new HashMap<String, String>();
				map.put("llkey",llkey);
				List<LicenseListExt> LLresultList = licenseListService.getLicenseListList(map);
				return LLresultList;
			}
	//修改LicenseList
	@RequestMapping("/updateLicenseList")
	public  String updateLicenseList(LicenseList LicenseList,Model model,HttpSession session,MultipartFile upload) {
		// 1.获取当前时间
				Date today = new Date();
				LicenseList.setCmModificationDate(today);
				//维护人
				User user=(User)session.getAttribute("user");
				String whModifyPerson=user.getUserId()+"";
				LicenseList.setCmModificationPerson(whModifyPerson);
				//文件上传
				
				String uploadFile_name = "";
				String newFileName = "";
				try {// 原始⽂件名称
					if (upload != null) {
				
						uploadFile_name = upload.getOriginalFilename();
						// 新⽂件名称
						if (!"".equals(uploadFile_name))
							newFileName = UUID.randomUUID().toString()
									+ uploadFile_name.substring(uploadFile_name
											.lastIndexOf("."));
						// 上传图⽚物理路径
						String url = session.getServletContext()
								.getRealPath("/LicenseList/upload");
						File uploadfile = new java.io.File(url + "/" + newFileName);
						File url1=new File(url);
						if (!url1.exists()) {
							url1.mkdirs();
						}
						upload.transferTo(uploadfile);
						LicenseList.setCmCertificateUrl(newFileName);
					}
				} catch (IllegalStateException e) {
					e.printStackTrace();
				} catch (IOException e) {
					e.printStackTrace();
				}
				licenseListService.updateLicenseList(LicenseList);
				return "redirect:clientMgrInfoOther1?pageNum=2&llkey="+LicenseList.getLlkey();
	}

	//添加RewardPunishment奖惩
	@RequestMapping("/addRewardPunishment")
	public  String addRewardPunishment(RewardPunishment rewardPunishment,Model model,HttpSession session,MultipartFile upload) {
		// 1.获取当前时间
				Date today = new Date();
				rewardPunishment.setRpModifyDate(today);
				User user=(User)session.getAttribute("user");
				String whModifyPerson=user.getUserId()+"";
				rewardPunishment.setRpModifyPerson(whModifyPerson);
				//文件上传
				
				String uploadFile_name = "";
				String newFileName = "";
				try {// 原始⽂件名称
					if (upload != null) {
				
						uploadFile_name = upload.getOriginalFilename();
						// 新⽂件名称
						if (!"".equals(uploadFile_name))
							newFileName = UUID.randomUUID().toString()
									+ uploadFile_name.substring(uploadFile_name
											.lastIndexOf("."));
						// 上传图⽚物理路径
						String url = session.getServletContext()
								.getRealPath("/rewardPunishment/upload");
						File uploadfile = new java.io.File(url + "/" + newFileName);
						File url1=new File(url);
						if (!url1.exists()) {
							url1.mkdirs();
						}
						upload.transferTo(uploadfile);
						rewardPunishment.setRpAttachment(newFileName);
					}
				} catch (IllegalStateException e) {
					e.printStackTrace();
				} catch (IOException e) {
					e.printStackTrace();
				}
				rpService.addRewardPunishment(rewardPunishment);
				return "redirect:clientMgrInfoOther1?pageNum=3&userId="+rewardPunishment.getUserId();
	}
	
	//查询RewardPunishment 修改过度
	@RequestMapping("/modifyRewardPunishment")
	public @ResponseBody List<RewardPunishmentExt> getRewardPunishment(String rpKey) {
		HashMap<String, String> map=new HashMap<String, String>();
		map.put("rpkey",rpKey);
		List<RewardPunishmentExt> RPresultList = rpService.getRewardPunishmentList(map);
		return RPresultList;
	}
	
	////修改RewardPunishment
	@RequestMapping("/updateRewardPunishment")
	public  String updateRewardPunishment(RewardPunishment rewardPunishment,Model model,HttpSession session,MultipartFile upload) {
		// 1.获取当前时间
				Date today = new Date();
				rewardPunishment.setRpModifyDate(today);
				User user=(User)session.getAttribute("user");
				String whModifyPerson=user.getUserId()+"";
				rewardPunishment.setRpModifyPerson(whModifyPerson);
				//文件上传
				
				String uploadFile_name = "";
				String newFileName = "";
				try {// 原始⽂件名称
					if (upload != null) {
				
						uploadFile_name = upload.getOriginalFilename();
						// 新⽂件名称
						if (!"".equals(uploadFile_name))
							newFileName = UUID.randomUUID().toString()
									+ uploadFile_name.substring(uploadFile_name
											.lastIndexOf("."));
						// 上传图⽚物理路径
						String url = session.getServletContext()
								.getRealPath("/rewardPunishment/upload");
						File uploadfile = new java.io.File(url + "/" + newFileName);
						File url1=new File(url);
						if (!url1.exists()) {
							url1.mkdirs();
						}
						upload.transferTo(uploadfile);
						rewardPunishment.setRpAttachment(newFileName);
					}
				} catch (IllegalStateException e) {
					e.printStackTrace();
				} catch (IOException e) {
					e.printStackTrace();
				}
				rpService.updateRewardPunishment(rewardPunishment);
				return "redirect:clientMgrInfoOther1?pageNum=3&rpKey="+rewardPunishment.getRpKey();
	}
	
	//添加考核记录
	@RequestMapping("/addCMass")
	public String addCMass(CMass cMass,Model model,HttpSession session,MultipartFile upload) {
		// 1.获取当前时间
				Date today = new Date();
				cMass.setGcmtdate(today);
				User user=(User)session.getAttribute("user");
				String whModifyPerson=user.getUserId()+"";
				cMass.setGcmapersonnel(whModifyPerson);
				
				//文件上传
				String uploadFile_name = "";
				String newFileName = "";
				try {// 原始⽂件名称
					if (upload != null) {
						uploadFile_name = upload.getOriginalFilename();
						// 新⽂件名称
						if (!"".equals(uploadFile_name))
							newFileName = UUID.randomUUID().toString()
									+ uploadFile_name.substring(uploadFile_name
											.lastIndexOf("."));
						// 上传图⽚物理路径
						String url = session.getServletContext()
								.getRealPath("/CMass/upload");
						File uploadfile = new java.io.File(url + "/" + newFileName);
						File url1=new File(url);
						if (!url1.exists()) {
							url1.mkdirs();
						}
						upload.transferTo(uploadfile);
						cMass.setGcattachment(newFileName);
					}
				} catch (IllegalStateException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				cMassService.addCMass(cMass);
				return "redirect:clientMgrInfoOther1?pageNum=4&userId="+cMass.getUserId();
	}
	
	//修改考核记录过渡
		@RequestMapping("/modifyCMass")
	public @ResponseBody List<CMassExt> getCMass(String clientgckey) {
			HashMap<String, String> map=new HashMap<String, String>();
			map.put("Clientgckey",clientgckey);
			List<CMassExt> cmassresultList = cMassService.getCMassList(map);
			return cmassresultList;
		}
		
	
	//修改考核记录
	@RequestMapping("/updateCMass")
	public String updateCMass(CMass cMass,Model model,HttpSession session,MultipartFile upload) {
		// 1.获取当前时间
				Date today = new Date();
				cMass.setGcmtdate(today);
				User user=(User)session.getAttribute("user");
				String whModifyPerson=user.getUserId()+"";
				cMass.setGcmapersonnel(whModifyPerson);
				
				//文件上传
				String uploadFile_name = "";
				String newFileName = "";
				try {// 原始⽂件名称
					if (upload != null) {
						uploadFile_name = upload.getOriginalFilename();
						// 新⽂件名称
						if (!"".equals(uploadFile_name))
							newFileName = UUID.randomUUID().toString()
									+ uploadFile_name.substring(uploadFile_name
											.lastIndexOf("."));
						// 上传图⽚物理路径
						String url = session.getServletContext()
								.getRealPath("/CMass/upload");
						File uploadfile = new java.io.File(url + "/" + newFileName);
						File url1=new File(url);
						if (!url1.exists()) {
							url1.mkdirs();
						}
						upload.transferTo(uploadfile);
						cMass.setGcattachment(newFileName);
					}
				} catch (IllegalStateException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				cMassService.updateCMass(cMass);
				return "redirect:clientMgrInfoOther1?pageNum=4&clientgckey="+cMass.getClientgckey();
	}
	//添加学习培训记录
	@RequestMapping("/addCMltr")
	public  String addCMltr(CMltr cMltr,Model model,HttpSession session,MultipartFile upload) {
		// 1.获取当前时间
				Date today = new Date();
				cMltr.setTrmodate(today);
				//维护人
				User user=(User)session.getAttribute("user");
				String whModifyPerson=user.getUserId()+"";
				cMltr.setTrmoperson(whModifyPerson);
				//文件上传
				
				String uploadFile_name = "";
				String newFileName = "";
				try {// 原始⽂件名称
					if (upload != null) {
				
						uploadFile_name = upload.getOriginalFilename();
						// 新⽂件名称
						if (!"".equals(uploadFile_name))
							newFileName = UUID.randomUUID().toString()
									+ uploadFile_name.substring(uploadFile_name
											.lastIndexOf("."));
						// 上传图⽚物理路径
						String url = session.getServletContext()
								.getRealPath("/CMltr/upload");
						File uploadfile = new java.io.File(url + "/" + newFileName);
						File url1=new File(url);
						if (!url1.exists()) {
							url1.mkdirs();
						}
						upload.transferTo(uploadfile);
						cMltr.setTrattachment(newFileName);
					}
				} catch (IllegalStateException e) {
					e.printStackTrace();
				} catch (IOException e) {
					e.printStackTrace();
				}
				cMltrService.addCMltr(cMltr);
				return "redirect:clientMgrInfoOther1?pageNum=5&userId="+cMltr.getUesrId();
	}
	
	//修改学习培训记录过渡
		@RequestMapping("/modifyCMltr")
	public @ResponseBody List<CMltrExt> getCMltr(String clienttkey) {
			HashMap<String, String> map=new HashMap<String, String>();
			map.put("Clienttkey",clienttkey);
			List<CMltrExt> cMltrresultList = cMltrService.getCMltrList(map);
			return cMltrresultList;
		}
	
	
	//修改学习培训记录
	@RequestMapping("/updateCMltr")
	public  String updateCMltr(CMltr cMltr,Model model,HttpSession session,MultipartFile upload) {
		// 1.获取当前时间
				Date today = new Date();
				cMltr.setTrmodate(today);
				//维护人
				User user=(User)session.getAttribute("user");
				String whModifyPerson=user.getUserId()+"";
				cMltr.setTrmoperson(whModifyPerson);
				//文件上传
				
				String uploadFile_name = "";
				String newFileName = "";
				try {// 原始⽂件名称
					if (upload != null) {
				
						uploadFile_name = upload.getOriginalFilename();
						// 新⽂件名称
						if (!"".equals(uploadFile_name))
							newFileName = UUID.randomUUID().toString()
									+ uploadFile_name.substring(uploadFile_name
											.lastIndexOf("."));
						// 上传图⽚物理路径
						String url = session.getServletContext()
								.getRealPath("/CMltr/upload");
						File uploadfile = new java.io.File(url + "/" + newFileName);
						File url1=new File(url);
						if (!url1.exists()) {
							url1.mkdirs();
						}
						upload.transferTo(uploadfile);
						cMltr.setTrattachment(newFileName);
					}
				} catch (IllegalStateException e) {
					e.printStackTrace();
				} catch (IOException e) {
					e.printStackTrace();
				}
				cMltrService.updateCMltr(cMltr);
				return "redirect:clientMgrInfoOther1?pageNum=5&clienttkey="+cMltr.getClienttkey();
	}
	
	//添加(等级认定记录)
	@RequestMapping("/addCMlevel")
	public String addCMlevel(CMlevel cMlevel,Model model,HttpSession session,MultipartFile upload) {
		// 1.获取当前时间
		Date today = new Date();
		cMlevel.setHodate(today);
		User user=(User)session.getAttribute("user");
		String whModifyPerson=user.getUserId()+"";
		cMlevel.setHoperson(whModifyPerson);
		
		//文件上传
		String uploadFile_name = "";
		String newFileName = "";
		try {// 原始⽂件名称
			if (upload != null) {
				uploadFile_name = upload.getOriginalFilename();
				// 新⽂件名称
				if (!"".equals(uploadFile_name))
					newFileName = UUID.randomUUID().toString()
							+ uploadFile_name.substring(uploadFile_name
									.lastIndexOf("."));
				// 上传图⽚物理路径
				String url = session.getServletContext()
						.getRealPath("/CMlevel/upload");
				File uploadfile = new java.io.File(url + "/" + newFileName);
				File url1=new File(url);
				if (!url1.exists()) {
					url1.mkdirs();
				}
				upload.transferTo(uploadfile);
				cMlevel.setHoattachment(newFileName);
			}
		} catch (IllegalStateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		cMlevelService.addCMlevel(cMlevel);
		return "redirect:clientMgrInfoOther1?pageNum=6&userId="+cMlevel.getUesrId();
	}
	//修改等级认定记录过渡
	@RequestMapping("/modifyCMlevel")
	public @ResponseBody List<CMlevelExt> getCMlevel(String clientlekey) {
		HashMap<String, String> map=new HashMap<String, String>();
		map.put("Clientlekey",clientlekey);
		List<CMlevelExt> cMlevelresultList = cMlevelService.getCMlevelList(map);
		return cMlevelresultList;
	}
	
	
	
	//添加(等级认定记录)
	@RequestMapping("/updateCMlevel")
	public String updateCMlevel(CMlevel cMlevel,Model model,HttpSession session,MultipartFile upload) {
		// 1.获取当前时间
		Date today = new Date();
		cMlevel.setHodate(today);
		User user=(User)session.getAttribute("user");
		String whModifyPerson=user.getUserId()+"";
		cMlevel.setHoperson(whModifyPerson);
		
		//文件上传
		String uploadFile_name = "";
		String newFileName = "";
		try {// 原始⽂件名称
			if (upload != null) {
				uploadFile_name = upload.getOriginalFilename();
				// 新⽂件名称
				if (!"".equals(uploadFile_name))
					newFileName = UUID.randomUUID().toString()
							+ uploadFile_name.substring(uploadFile_name
									.lastIndexOf("."));
				// 上传图⽚物理路径
				String url = session.getServletContext()
						.getRealPath("/CMlevel/upload");
				File uploadfile = new java.io.File(url + "/" + newFileName);
				File url1=new File(url);
				if (!url1.exists()) {
					url1.mkdirs();
				}
				upload.transferTo(uploadfile);
				cMlevel.setHoattachment(newFileName);
			}
		} catch (IllegalStateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		cMlevelService.updateCMlevel(cMlevel);
		return "redirect:clientMgrInfoOther1?pageNum=6&clientlekey="+cMlevel.getClientlekey();
	}
	
	
	
	//修改workh过渡
	@RequestMapping("/modifyWork")
	public @ResponseBody List<WorkHistoryExt> getWorkHistory(String cmKey) {
		HashMap<String, String> map=new HashMap<String, String>();
		map.put("whkey",cmKey);
		List<WorkHistoryExt> workList = workHistoryService.getWorkList(map);
		return workList;
	}
	
	//添加workh
	@RequestMapping("/addWorkHistory")
	public String addWorkHistory(WorkHistory workHistory,Model model,HttpSession session,MultipartFile upload) {
		// 1.获取当前时间
		Date today = new Date();
		workHistory.setWhModifyDate(today);
		User user=(User)session.getAttribute("user");
		String whModifyPerson=user.getUserId()+"";
		workHistory.setWhModifyPerson(whModifyPerson);
		
		//文件上传
		String uploadFile_name = "";
		String newFileName = "";
		try {// 原始⽂件名称
			if (upload != null) {
				uploadFile_name = upload.getOriginalFilename();
				// 新⽂件名称
				if (!"".equals(uploadFile_name))
					newFileName = UUID.randomUUID().toString()
							+ uploadFile_name.substring(uploadFile_name
									.lastIndexOf("."));
				// 上传图⽚物理路径
				String url = session.getServletContext()
						.getRealPath("/mgrWorkHist/upload");
				File uploadfile = new java.io.File(url + "/" + newFileName);
				File url1=new File(url);
				if (!url1.exists()) {
					url1.mkdirs();
				}
				upload.transferTo(uploadfile);
				workHistory.setWhAttachment(newFileName);
			}
		} catch (IllegalStateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		workHistoryService.addWorkHistory(workHistory);
		return "redirect:clientMgrInfoOther1?pageNum=1&userId="+workHistory.getUserId();
	}
	
		
	//修改workH
	@RequestMapping("/updateWorkHistory")
	public String updateWorkHistory(WorkHistory hist, Model model,MultipartFile upload,HttpServletRequest req) {
		String uploadFile_name = "";
		String newFileName = "";
		try {// 原始⽂件名称
			if (upload != null) {
				uploadFile_name = upload.getOriginalFilename();
				// 新⽂件名称
				if (!"".equals(uploadFile_name))
					newFileName = UUID.randomUUID().toString()
							+ uploadFile_name.substring(uploadFile_name
									.lastIndexOf("."));
				// 上传图⽚物理路径
				String url = req.getSession().getServletContext()
						.getRealPath("/mgrWorkHist/upload");
				File uploadfile = new java.io.File(url + "/" + newFileName);
				File url1=new File(url);
				if (!url1.exists()) {
					url1.mkdirs();
				}
				upload.transferTo(uploadfile);
				hist.setWhAttachment(newFileName);
			}
		} catch (IllegalStateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		// 1.获取当前时间
		Date today = new Date();
		hist.setWhModifyDate(today);
		workHistoryService.updateWorkHistory(hist);
		return "redirect:clientMgrInfoOther?pageNum=7&whkey="+hist.getWhkey();
	}


	@ModelAttribute("mgrLevel")
	public Map<String, String> getMgrLevelList() {
		Map<String, String> levelParam = new HashMap<String, String>();
		List<Param> paramList = paramService
				.getParamList(Constant.PARAM_TYPE_MGRLEVEL);
		if (paramList != null && paramList.size() > 0) {
			for (int i = 0; i < paramList.size(); i++) {
				Param param = paramList.get(i);
				levelParam.put(param.getCode(), param.getParamName());
			}
		}
		return levelParam;
	}
	//删除deleteOther?keys="+ids+"&scanLog="+scanLog; 
	@RequestMapping("/deleteOther")
	public String deleteOther(String keys,String scanLog) {
		String keysId[] = keys.split(",");
		String user_ids[] = new String[keysId.length];
		for(int i=0;i<keysId.length;i++){
			user_ids[i] = keysId[i];
		}
		if(scanLog.equals("1")) {
			cmResultsService.deleteCMResults(user_ids);
		}else if(scanLog.equals("2")) {
			licenseListService.deleteLicenseList(user_ids);
		}else if(scanLog.equals("3")) {
			rpService.deleteRewardPunishment(user_ids);
		}else if(scanLog.equals("4")) {
			cMassService.deleteCMass(user_ids);
		}else if(scanLog.equals("5")) {
			cMltrService.deleteCMltr(user_ids);
		}else if(scanLog.equals("6")) {
			cMlevelService.deleteCMlevel(user_ids);
		}else if(scanLog.equals("7")) {
			workHistoryService.deleteWorkHistory(user_ids);
		}
		
		return "redirect:clientMgrInfoOther1?pageNum="+scanLog;
		
	}
	//下载文件
	@RequestMapping("/downLoadFile2")
	public ResponseEntity<byte[]> downFile2(String fileName,HttpServletRequest req,String pageNum) throws IOException {
//		String url = req.getSession().getServletContext().getRealPath("/upload/meet");
//		File file = new File(url + "/" + fileName);
		String url ="";
		File file = null;
		if(pageNum.equals("1")) {
			url = req.getSession().getServletContext().getRealPath("/CMResults/upload");
			file = new File(url + "/" + fileName);
		}else if(pageNum.equals("2")) {
			url = req.getSession().getServletContext().getRealPath("/LicenseList/upload");
			file = new File(url + "/" + fileName);
		}else if(pageNum.equals("3")) {
			url = req.getSession().getServletContext().getRealPath("/rewardPunishment/upload");
			file = new File(url + "/" + fileName);
		}else if(pageNum.equals("4")) {
			url = req.getSession().getServletContext().getRealPath("/CMass/upload");
			file = new File(url + "/" + fileName);
		}else if(pageNum.equals("5")) {
			url = req.getSession().getServletContext().getRealPath("/CMltr/upload");
			file = new File(url + "/" + fileName);
		}else if(pageNum.equals("6")) {
			url = req.getSession().getServletContext().getRealPath("/CMlevel/upload");
			file = new File(url + "/" + fileName);
		}else if(pageNum.equals("7")) {
			url = req.getSession().getServletContext().getRealPath("/mgrWorkHist/upload");
			file = new File(url + "/" + fileName);
		}
		HttpHeaders headers = new HttpHeaders();
		// 下载显示的⽂件名，解决中⽂名称乱码问题
		String downloadFielName = new String(fileName.getBytes("UTF-8"),
				"iso-8859-1");
		// 通知浏览器以attachment（下载⽅式）打开图⽚
		headers.setContentDispositionFormData("attachment", downloadFielName);
		// application/octet-stream：⼆进制流数据（最常⻅的⽂件下载）。
			headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
			return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(file),
					headers, HttpStatus.CREATED);
	}
	
}
